﻿Imports SIAVU.Dominio

Partial Public Class ucBusqueda
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        chkMostrarInconsistentes.Visible = mostrarCheckInconsitentes
        'For i As Integer = 0 To gvResultados.Columns.Count - 1
        '    gvResultados.Columns(i).Visible = True
        'Next i
        'gvResultados.Settings.ShowVerticalScrollBar = True
    End Sub

#Region "Variables"
    Private _mostrarCheckInconsitentes As Boolean
#End Region

#Region "Propiedades"
    <System.ComponentModel.DefaultValue(False)> _
    Public Property mostrarCheckInconsitentes() As Boolean
        Get
            Return _mostrarCheckInconsitentes
        End Get
        Set(ByVal value As Boolean)
            _mostrarCheckInconsitentes = value
        End Set
    End Property
#End Region

#Region "Eventos"

    Protected Sub btnBuscar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnBuscar.Click
        CargarGrilla()
    End Sub

    Protected Sub odsAviones_Selected(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs) Handles odsAviones.Selected
        Dim oAviones As IList(Of Avion) = e.ReturnValue
        Dim oAvion As New Avion
        oAvion.AvionID = 0
        oAvion.Descripcion = ""
        oAviones.Add(oAvion)
    End Sub

    Protected Sub btnVerDetalle_Click(ByVal sender As Object, ByVal e As EventArgs)

        Try
            Me.Visible = False
            Session("UsuarioIDucMiProgramacion") = CInt(DirectCast(sender, DevExpress.Web.ASPxEditors.ASPxButton).CommandArgument)
            If (Me.Page.AppRelativeVirtualPath.ToUpper = "~/PRESENTACION/VERHISTORIAL.ASPX") Then
                DirectCast(Me.Page, SIAVU.Presentacion.VerHistorial).PanelHistorialVisible = True
                DirectCast(Me.Page, SIAVU.Presentacion.VerHistorial).SetearControles()

            ElseIf Me.Page.AppRelativeVirtualPath.ToUpper = "~/PRESENTACION/REPROGRAMARTRIPULANTES.ASPX" Then
                DirectCast(Me.Page, SIAVU.Presentacion.ReprogramarTripulantes).PanelReprogramacionVisible = True
                DirectCast(Me.Page, SIAVU.Presentacion.ReprogramarTripulantes).SetearControles()
                DirectCast(Me.Page, SIAVU.Presentacion.ReprogramarTripulantes).ucMiProgramacion1.LimpiarSession()
            End If

        Catch ex As Exception
            Me.Visible = True
            Throw
            'TODO Mandar a pagina de error
        End Try

    End Sub

#End Region

#Region "Métodos"

    Private Sub CargarGrilla()

        Dim oEntityManager As New EntityManager

        Dim AvionID As Long = 0
        If cmbTipoAvion.SelectedItem IsNot Nothing Then
            AvionID = cmbTipoAvion.SelectedItem.Value
        End If

        gvResultados.DataSource = oEntityManager.getUsuariosControlBusqueda(IIf(txtLegajo.Text.Trim = "0", Nothing, txtLegajo.Text), _
                                                                            IIf(txtApellido.Text.Trim = String.Empty, Nothing, txtApellido.Text), _
                                                                            AvionID, _
                                                                            chkMostrarInconsistentes.Checked)

        gvResultados.AutoGenerateColumns = False

        gvResultados.DataBind()
    End Sub

#End Region

End Class